package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.CouponGoodsListAdapter;
import com.jl.jlapp.eneity.CouponMsgModel;
import com.jl.jlapp.eneity.CouponMsgModel.ResultDataBean.GoodsBean;
import com.jl.jlapp.eneity.CouponMsgModel.ResultDataBean.GoodsBean.GoodsSpecificationDetailsBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.eneity.PresellMsg;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.utils.Tools;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;

public class CouponHasGoodsListActivity
  extends AppCompatActivity
{
  int activityId = 0;
  String activityName = "";
  @BindView(R.id.back)
  ImageView back;
  int couponId = 0;
  CouponGoodsListAdapter goodsListAdapter;
  private ProgressDialog progressDialog;
  @BindView(R.id.recyclerView)
  RecyclerView recyclerView;
  List<CouponMsgModel.ResultDataBean.GoodsBean> resultDataBeans = new ArrayList();
  @BindView(R.id.title)
  TextView title;
  int userId = 0;
  int whichOperation = 0;
  
  public void buildProgressDialog()
  {
    if (this.progressDialog == null)
    {
      this.progressDialog = new ProgressDialog(this);
      this.progressDialog.setProgressStyle(0);
    }
    this.progressDialog.setMessage("加载中");
    this.progressDialog.setCancelable(true);
    this.progressDialog.show();
  }
  
  public void cancelProgressDialog()
  {
    if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
      this.progressDialog.dismiss();
    }
  }
  
  public void getGoodsList(int paramInt)
  {
    Net.get().getMsgByCouponId(paramInt).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new CommonObserver<CouponMsgModel>() {
              @Override
              protected void onError(String errorMsg) {

              }

              @Override
              protected void onSuccess(CouponMsgModel couponMsgModel) {

              }
            });
  }
  
  public void getPreSellActivityInformationByGoodsDetailsId(Integer paramInteger1, Integer paramInteger2)
  {
    Net.get().getPreSellActivityInformationByGoodsDetailsId(((CouponMsgModel.ResultDataBean.GoodsBean)this.resultDataBeans.get(paramInteger1.intValue())).getId(), this.couponId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).
            subscribe(new CommonObserver<PresellMsg>() {
              @Override
              protected void onError(String errorMsg) {

              }

              @Override
              protected void onSuccess(PresellMsg presellMsg) {

              }
            });
  }
  
  public void insertShoppingCart(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4, Integer paramInteger5, String paramString)
  {
    Net.get().insertShoppingCart(paramInteger1.intValue(), paramInteger2.intValue(), paramInteger3.intValue(), paramInteger4.intValue(), paramInteger5.intValue(), paramString).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()
    ).subscribe(new CommonObserver<PostModel>() {
      @Override
      protected void onError(String errorMsg) {

      }

      @Override
      protected void onSuccess(PostModel postModel) {

      }
    });
  }
  
  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(R.layout.no_sort_goods_list_layout);
    ButterKnife.bind(this);
    Tools.addActivity(this);
    this.couponId = getIntent().getIntExtra("couponId", -1);
    this.back.setOnClickListener(new OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        CouponHasGoodsListActivity.this.finish();
      }
    });
    buildProgressDialog();
    if (this.couponId == -1)
    {
      Toast.makeText(this, "页面传值出错...", Toast.LENGTH_SHORT).show();
      return;
    }
    getGoodsList(this.couponId);
  }
  
  protected void onResume()
  {
    super.onResume();
    this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
  }
  
  public void setAdapter()
  {
    this.recyclerView.setLayoutManager(new LinearLayoutManager(this));
    this.goodsListAdapter = new CouponGoodsListAdapter(R.layout.goods_list_item, this.resultDataBeans);
    this.recyclerView.setAdapter(this.goodsListAdapter);
    this.goodsListAdapter.setOnItemClickListener(new OnItemClickListener()
    {
      public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt)
      {
        CouponHasGoodsListActivity.this.whichOperation = 1;
        int i = Integer.parseInt((String)((TextView)paramAnonymousView.findViewById(R.id.goods_id)).getText());
        if (((CouponMsgModel.ResultDataBean.GoodsBean.GoodsSpecificationDetailsBean)((CouponMsgModel.ResultDataBean.GoodsBean)CouponHasGoodsListActivity.this.resultDataBeans.get(paramAnonymousInt)).getGoodsSpecificationDetails().get(0)).getGxcGoodsState() == 2)
        {
          Intent intent = new Intent(CouponHasGoodsListActivity.this, GoodsDetailActivity.class);
          intent.putExtra("goodsId", i);
          CouponHasGoodsListActivity.this.startActivity(intent);
          return;
        }
        CouponHasGoodsListActivity.this.getPreSellActivityInformationByGoodsDetailsId(Integer.valueOf(paramAnonymousInt), Integer.valueOf(i));
      }
    });
    this.goodsListAdapter.setOnItemChildClickListener(new OnItemChildClickListener()
    {
      public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt)
      {
        CouponHasGoodsListActivity.this.whichOperation = 2;
        if (CouponHasGoodsListActivity.this.userId > 0)
        {
          if (((CouponMsgModel.ResultDataBean.GoodsBean.GoodsSpecificationDetailsBean)((CouponMsgModel.ResultDataBean.GoodsBean)CouponHasGoodsListActivity.this.resultDataBeans.get(paramAnonymousInt)).getGoodsSpecificationDetails().get(0)).getGxcGoodsState() == 2)
          {
            CouponHasGoodsListActivity.this.activityId = 0;
            CouponHasGoodsListActivity.this.activityName = "";
            CouponHasGoodsListActivity.this.insertShoppingCart(Integer.valueOf(CouponHasGoodsListActivity.this.userId), Integer.valueOf(((CouponMsgModel.ResultDataBean.GoodsBean)CouponHasGoodsListActivity.this.resultDataBeans.get(paramAnonymousInt)).getId()), Integer.valueOf(((CouponMsgModel.ResultDataBean.GoodsBean.GoodsSpecificationDetailsBean)((CouponMsgModel.ResultDataBean.GoodsBean)CouponHasGoodsListActivity.this.resultDataBeans.get(paramAnonymousInt)).getGoodsSpecificationDetails().get(0)).getId()), Integer.valueOf(1), Integer.valueOf(CouponHasGoodsListActivity.this.activityId), CouponHasGoodsListActivity.this.activityName);
            return;
          }
          CouponHasGoodsListActivity.this.getPreSellActivityInformationByGoodsDetailsId(Integer.valueOf(paramAnonymousInt), Integer.valueOf(0));
          return;
        }
        Toast.makeText(CouponHasGoodsListActivity.this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(CouponHasGoodsListActivity.this, LoginActivity.class);
        CouponHasGoodsListActivity.this.startActivity(intent);
      }
    });
  }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/CouponHasGoodsListActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */